package com.zzyl.serve.controller.member;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.serve.domain.PageDto;
import com.zzyl.serve.domain.PageResult;
import com.zzyl.serve.vo.CountByTimeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.serve.domain.Reservation;
import com.zzyl.serve.service.IReservationService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 预约信息Controller
 * 
 * @author huangqin
 * @date 2025-05-08
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "预约信息相关接口")
public class ReservationController extends BaseController
{
    @Autowired
    private IReservationService reservationService;

/**
 * 2.1 查询当天取消预约数量
 * - 接口地址:/member/reservation/cancelled-count
 * - 请求方式:GET
 */
@GetMapping("/cancelled-count")
@ApiOperation("查询当天取消预约数量")
public AjaxResult getCancelledCount() {
    Long count = reservationService.getCancelledCount();
    return AjaxResult.success(count);
}

/**
 * 2.3 新增预约
 * - 接口地址:/member/reservation/
 * - 请求方式:POST
 */
    @PostMapping()
    @ApiOperation("新增预约")
    public AjaxResult add(@RequestBody Reservation reservation) {
        reservationService.saveReservation(reservation);
        return AjaxResult.success();
}

/**
 * 2.2 查询每个时间段剩余预约次数
 * - 接口地址:/member/reservation/countByTime
 * - 请求方式:GET
 */
    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public AjaxResult countByTime(@RequestParam long time) {
        List<CountByTimeVo> countByTimeVos = reservationService.countByTime(time);
        return AjaxResult.success(countByTimeVos);
    }

/**
 * 2.4 分页查询预约
 * - 接口地址:/member/reservation/page
 * - 请求方式:GET
 */
    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    public AjaxResult list(PageDto pageDto){
       PageResult pageResult = reservationService.listService(pageDto);
       return AjaxResult.success(pageResult);
    }

/**
 * 2.5 取消预约
 * - 接口地址:/member/reservation/{id}/cancel
 * - 请求方式:PUT
 */
    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public AjaxResult cancel(@PathVariable Long id) {
        reservationService.cancelReservation(id);
        return AjaxResult.success();
    }
}
